<template>
  <div class="applyOf login">
    <div class="flex justify_between align_center">
      <div class="underline" style="width: 120px">
        <span class="title1 color1 zIndex fontBold" v-if="route.query.type == -1 || route.query.type == 1">入会申请</span>
        <span class="title1 color1 zIndex fontBold" v-if="route.query.type == 2">银行转账</span>
      </div>
      <div class="customer flex justify_center align_center" @click="show = true">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-lianxiwomen" />
        </svg>
        <span class="font400 content3">联系我们</span>
      </div>
    </div>
    <div class="login_content">
      <div class="applyOf_tisp flex justify_center align_center flex_column" v-if="route.query.type == 1">
        <img src="@/assets/img/8e5161ad373d54208afd1bef7d27fcc.png">
        <p class="color1 fontBold content7">
          入会申请已提交
        </p>
        <p class="font400 content3 color3">
          请耐心等待审核结果
        </p>
      </div>
      <div class="applyOf_tisp flex justify_center align_center flex_column" v-if="route.query.type == -1">
        <img src="@/assets/img/wtg.png">
        <p class="color1 fontBold content7">
          入会申请未通过
        </p>
        <p class="font400 content3 color3">
          请重新申请
        </p>
      </div>
      <div class="contentInfo" v-if="data.create_time">
        <div class="contentInfoBox flex justify_between flex_column">
          <p class="font400 content3 color3">
            <!-- 会员续费 / 副会长单位 -->
            <span class="font400 content3 color3" v-if="data.pay_type == 1 && data.is_apply == 0">会员续费 /</span>
            <span class="font400 content3 color3" v-if="data.pay_type == 2">活动报名 /
            </span>
            <span class="font400 content3 color3" v-if="data.pay_type == 3">课程报名 /
            </span>
            <span class="font400 content3 color3" v-if="data.pay_type == 1 && data.is_apply == 1">企业入会 /
            </span>
            {{ data.company_level || data.title }}
          </p>
          <p class="font400 content2 color6">
            {{ data.create_time }}
          </p>
        </div>
      </div>
      <div class="contentInfo" v-if="data.receipt_url">
        <div class="contentInfoBox flex align_center justify_between">
          <div class=" flex align_center">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-a-7" />
            </svg>
            <span>报名回执</span>
          </div>

          <div @click="downPdf(data.paid_id)" class="copy font400 color4 content2">
            下载
          </div>
        </div>
      </div>
      <div class="Membership" v-if="route.query.type == 2">
        <div class="MembershipBox">
          <div class="MembershipBoxHeader flex justify_between align_center">
            <!-- <p class="font400 content3 color3">
              待支付会费：
            </p> -->
            <p class="content4 color2 font400">
              ￥{{ data.price }}
            </p>
          </div>
          <div class="MembershipContent">
            <p class="font400 content3 color3">
              订单已生成，请将费用转入指定银行账户,并复制备注信息，填写在转账备注中。耐心等待工作人员审核。
            </p>
            <p class="font400 content3 color3">
              转账信息如下，请在转账时备注指定信息，可将以下信息进行复制。
            </p>
          </div>
          <div class="MembershipInfo">
            <p>
              <span class="font400 content3 color2">户名:</span>
              <!-- <span class="font400 content3 color6">{{ data.pay_type == 2 || data.pay_type == 3 ? "深房联企（深圳）投资发展有限公司" : "深圳市房地产协会" }}</span> -->
              <span class="font400 content3 color6">{{ data?.merchantInformation?.bank_account_name }}</span>
            </p>
            <p>
              <span class="font400 content3 color2">汇款账号:</span>
              <!-- <span class="font400 content3 color6">{{ data.pay_type == 2 || data.pay_type == 3 ? "443899991010004658527" : "231454674797941" }}</span> -->
              <span class="font400 content3 color6">{{ data?.merchantInformation?.remittance_account }}</span>
            </p>
            <p>
              <span class="font400 content3 color2">银行:</span>
              <!-- <span class="font400 content3 color6">交通银行深圳燕南支行</span> -->
              <span class="font400 content3 color6">{{ data?.merchantInformation?.bank_account }}</span>
            </p>
            <p>
              <span class="font400 content3 color2">汇款金额:</span>
              <span class="font400 content3 color6">{{ data.price }}</span>
            </p>
            <p>
              <span class="font400 content3 color2">备注信息:</span>
              <span class="font400 content3 color6">（{{ data.out_trade_no }}）{{ store.state.userInfo.company }}-{{
                data.company_level || data.title
              }}-{{
  data.pay_type == 2 || data.pay_type == 3
  ? "报名费 "
  : "会费 "
}}：{{ data.price }}</span>
            </p>
          </div>
          <div class="copy font400 color4 content2" @click="copy">
            复制信息
          </div>
        </div>
      </div>
      <div class="ewm flex justify_between align_center">
        <div class="ewm_box flex justify_between align_center">
          <div class="ewm_left">
            <img src="/src/assets/img/logo.png">
            <p class="font400 content3 color3">
              长按关注深圳房协公众号 了解我们的最新动态
            </p>
          </div>
          <div class="ewm_right">
            <img src="/src/assets/img/ewm.png">
          </div>
        </div>
      </div>
      <van-dialog v-model:show="show" title="温馨提示" confirm-button-color="#FF7A1F">
        <div class="Scan">
          <p class="font400 content3 color3">
            您可长按添加工作人员微信 与我们取得联系
          </p>
          <img src="@/assets/img/no-content-color.png">
        </div>
      </van-dialog>
      <van-dialog v-model:show="showQrCode" @confirm="closeQrCode" title="温馨提示" :close-on-click-overlay="false"
        confirm-button-color="#FF7A1F">
        <div class="Scan">
          <p class="font400 content3 color3">
            长按识别二维码，进入本期活动微信群
          </p>
          <img :src="qrCodeUrl">
        </div>
      </van-dialog>
      <p class="understand content3 font400 color3" @click="
        router.push({
          path: '/otherServices/introduce',
          query: { type: '1' },
        })
        ">
        了解深圳房地产协会 >
      </p>
    </div>
  </div>
  <div class="fexd_footer">
    <div v-if="data.status == 2 && data.is_invoice == 1" class="footer_btn flex align_center justify_between">
      <div class="font400 content3 color4" @click="back">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-fanhui" />
        </svg>
        <p class="content2 font400 color3">
          返回
        </p>
      </div>
      <div @click="handleGetAuthUrl" class="btn_item qr font400 content3 color4">
        申请开票
      </div>
    </div>
    <div v-else class="footer_btn flex align_center justify_between">
      <div @click="reapply" class="btn_item qr font400 content3 color4" v-if="route.query.type == -1">
        重新申请
      </div>
      <div @click="back" class="btn_item cancle font400 content3 color4" v-if="route.query.type != -1">
        返回
      </div>
    </div>

  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { orderInfo, getActivityQrcode, createActivityReceipt } from '@/api'
import { useRouter, useRoute } from 'vue-router'
import { useStore } from 'vuex'
import useClipboard from 'vue-clipboard3'
import { Toast } from 'vant'

const show: any = ref(false)
const showQrCode: any = ref(false)
const qrCodeUrl: any = ref('')
const data: any = ref([])
const router = useRouter()
const route = useRoute()
// const text = ref('户名：深圳市房地产协会 汇款账号：231454674797941 银行：交通银行深圳燕南支行 汇款金额： 备注信息：万科企业股份有限公司-监事长单位 会费：¥20000.00')
const store = useStore()

const getData = async () => {
  data.value = await orderInfo({ order_id: route.query.orderId })
  await getQrcode()
  await store.dispatch('fetchUserInfo')
}
getData()

const copy = async () => {
  try {
    // const bankMsg = data.value.pay_type === '2' || data.value.pay_type === '3' ? '深房联企（深圳）投资发展有限公司 汇款账号：443899991010004658527' : '深圳市房地产协会 汇款账号：231454674797941'
    const bankMsg = `${data.value?.merchantInformation?.bank_account_name} 汇款账号：${data.value?.merchantInformation?.remittance_account}`
    const { toClipboard } = useClipboard()
    const text: any = `户名：${bankMsg} 银行：${data.value?.merchantInformation?.bank_account} 汇款金额：${data.value.price
      } 备注信息：（${data.value?.out_trade_no}）${store.state.userInfo.company}-${data.value.company_level || data.value.title
      } ${data.value.pay_type === '2' || data.value.pay_type === '3'
        ? '报名费 '
        : '会费 '
      }：¥${data.value.price}`
    await toClipboard(text)
    Toast('复制成功')
  } catch (e) {
    console.error(e)
  }
}

const back = () => {
  // router.replace('/userCenter')
  console.log(store.state.from.path)
  if (route.query.active_id) {
    router.replace({ path: '/find/activity', query: { id: route.query.active_id } })
  } else if (route.query.book_id) {
    router.replace({ path: '/find/curriculum', query: { id: route.query.book_id } })
  } else if (route.query.back) {
    router.replace('/otherServices/order')
  } else {
    router.replace('/userCenter')
  }
  // router.replace(store.state.from.path)
  // if (store.state.from.path !== '/') {
  //   router.replace(store.state.from.path)
  // } else {
  //   router.replace('/userCenter')
  // }
}

const handleGetAuthUrl = () => {
  // otherServices/Invoicing
  // invoiceGetAuthUrl({ order_id: data.value.id }).then((res: any) => {
  //   window.location.href = res.auth_url
  // })
  router.replace('/otherServices/cost')
}

const getQrcode = () => {
  if (route.query.active_id || data.value.paid_id) {
    getActivityQrcode({ activity_id: route.query.active_id || data.value.paid_id }).then((res: any) => {
      if (res.url) {
        showQrCode.value = true
        qrCodeUrl.value = res.url
      }
    })
  }
}

const downPdf = (id: any) => {
  createActivityReceipt({
    activity_id: id,
    order_id: data.value.id
  }).then((res: any) => {
    console.log(res.receipt_url)
    window.location.href = res.receipt_url

    // const link = document.createElement('a')
    // link.setAttribute('href', res.receipt_url)
    // link.setAttribute('download', 'word.docx')
    // link.target = '_blank'
    // link.style.visibility = 'hidden'
    // document.body.appendChild(link)
    // link.click()
    // document.body.removeChild(link)
  })
}

const closeQrCode = () => {
  showQrCode.value = false
}

const reapply = () => {
  router.replace('/agreement')
}
</script>

<style lang="less" scoped>
.applyOf {
  padding: 0 30px 80px;
  margin-top: 40px;

  .customer {
    width: 93px;
    height: 32px;
    border: 1px solid #ff7a1f;
    border-radius: 5px;
    width: 111px;
    line-height: 32px;
    text-align: center;

    .icon {
      width: 22px;
      height: 22px;
    }

    span {
      margin-left: 4px;
      color: #ff7a1f;
    }
  }

  .login_content {
    margin-top: 20px;

    .contentInfo {
      width: 100%;
      background: #fff;
      border-radius: 10px;
      margin: 20px 0;

      .contentInfoBox {
        padding: 15px;

        p:last-child {
          margin-top: 25px;
        }

        .icon {
          width: 22px;
          height: 22px;
          margin-right: 5px;
        }

        .copy {
          width: 82px;
          height: 30px;
          background: #12142e;
          border-radius: 5px;
          text-align: center;
          line-height: 30px;
        }
      }
    }

    .understand {
      margin-top: 30px;
      text-align: center;
      text-decoration: underline;
    }

    .applyOf_tisp {
      width: 100%;
      height: 286px;
      background: #ffffff;
      border-radius: 5px;
      text-align: center;

      img {
        width: 170px;
        height: 150px;
        object-fit: contain;
        margin: 0 auto 20px;
      }

      p:last-child {
        margin-top: 10px;
      }
    }

    .ewm {
      width: 100%;
      height: 114px;
      background: #ffffff;
      border-radius: 5px;
      margin-top: 16px;

      .ewm_box {
        width: 100%;
        padding: 0 15px;

        .ewm_left {
          img {
            width: 100px;
            height: 30px;
            object-fit: contain;
          }

          p {
            width: 180px;
            margin-top: 14px;
            line-height: 18px;
          }
        }

        .ewm_right {
          width: 74px;
          height: 74px;

          img {
            width: 74px;
            height: 74px;
            object-fit: contain;
          }
        }
      }
    }
  }

  .leftw {
    width: 90px;
    display: inline-block;
  }

  .line {
    margin: 0 30px;
  }

  .setBnt {
    width: 98px;
    height: 30px;
    background: #12142e;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 400;
  }

  .Scan {
    p {
      width: 190px;
      margin: 18px auto;
      text-align: center;
      line-height: 20px;
    }

    img {
      width: 120px;
      height: 120px;
      object-fit: contain;
      margin: 0 auto 20px auto;
    }
  }

  .Membership {
    width: 100%;
    background: #ffffff;
    border-radius: 5px;

    .MembershipBox {
      padding: 15px;
    }

    .MembershipContent {
      margin-top: 30px;
      margin-bottom: 30px;

      p {
        line-height: 20px;
      }

      p:last-child {
        margin-top: 20px;
      }
    }

    .MembershipInfo {
      margin-bottom: 20px;

      p {
        margin-bottom: 5px;

        span:last-child {
          margin-left: 5px;
        }
      }
    }

    .copy {
      width: 82px;
      height: 30px;
      background: #12142e;
      border-radius: 5px;
      text-align: center;
      line-height: 30px;
    }
  }
}

// .fexd_footer {
//   position: fixed;
//   bottom: 0;
//   left: 0;
//   width: 100%;
//   height: 70px;
//   background-color: #fff;
//   box-shadow: 0px 2px 12px 2px rgba(22, 12, 6, 0.09);

//   .icon {
//     width: 23px;
//     height: 23px;
//     margin-bottom: 2px;
//   }
//   .footer_btn {
//     padding: 0 30px;
//     height: 100%;

//     .agree {
//       width: 140px;
//       height: 44px;
//       background: #ff7a1f;
//       border-radius: 5px;
//       text-align: center;
//       line-height: 44px;
//     }
//     .cancle {
//       width: 100%;
//       height: 44px;
//       background: #85898c;
//       border-radius: 5px;
//       text-align: center;
//       line-height: 44px;
//     }

//     .qr {
//       width: 100%;
//       height: 44px;
//       background: #ff7a1f;
//       border-radius: 5px;
//       text-align: center;
//       line-height: 44px;
//     }
//   }
// }
.fexd_footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 70px;
  background-color: #fff;
  box-shadow: 0px 2px 12px 2px rgba(22, 12, 6, 0.09);

  .icon {
    width: 23px;
    height: 23px;
    margin-bottom: 2px;
  }

  .footer_btn {
    padding: 0 30px;
    height: 100%;

    .cancle {
      width: 100%;
      height: 44px;
      background: #85898c;
      border-radius: 5px;
      text-align: center;
      line-height: 44px;
    }

    .qr {
      width: 189px;
      height: 44px;
      background: #ff7a1f;
      border-radius: 5px;
      text-align: center;
      line-height: 44px;
    }
  }
}

@media (min-width: 750px) {
  .applyOf {
    padding: 0 30px 80px;
    margin-top: 40px;

    .customer {
      width: 93px;
      height: 32px;
      border: 1px solid #ff7a1f;
      border-radius: 5px;
      width: 111px;
      line-height: 32px;
      text-align: center;

      .icon {
        width: 22px;
        height: 22px;
      }

      span {
        margin-left: 4px;
        color: #ff7a1f;
      }
    }

    .login_content {
      margin-top: 20px;

      .contentInfo {
        width: 100%;
        background: #fff;
        border-radius: 10px;
        margin: 20px 0;

        .contentInfoBox {
          padding: 15px;

          p:last-child {
            margin-top: 25px;
          }
        }
      }

      .understand {
        margin-top: 30px;
        text-align: center;
        text-decoration: underline;
      }

      .applyOf_tisp {
        width: 100%;
        height: 286px;
        background: #ffffff;
        border-radius: 5px;
        text-align: center;

        img {
          width: 170px;
          height: 150px;
          object-fit: contain;
          margin: 0 auto 20px;
        }

        p:last-child {
          margin-top: 10px;
        }
      }

      .ewm {
        width: 100%;
        height: 114px;
        background: #ffffff;
        border-radius: 5px;
        margin-top: 16px;

        .ewm_box {
          width: 100%;
          padding: 0 15px;

          .ewm_left {
            img {
              width: 100px;
              height: 30px;
              object-fit: contain;
            }

            p {
              width: 180px;
              margin-top: 14px;
              line-height: 18px;
            }
          }

          .ewm_right {
            width: 74px;
            height: 74px;

            img {
              width: 74px;
              height: 74px;
              object-fit: contain;
            }
          }
        }
      }
    }

    .leftw {
      width: 90px;
      display: inline-block;
    }

    .line {
      margin: 0 30px;
    }

    .setBnt {
      width: 98px;
      height: 30px;
      background: #12142e;
      border-radius: 5px;
      font-size: 14px;
      font-weight: 400;
    }

    .Scan {
      p {
        width: 190px;
        margin: 18px auto;
        text-align: center;
        line-height: 20px;
      }

      img {
        width: 95px;
        height: 95px;
        object-fit: contain;
        margin: 0 auto;
      }
    }

    .Membership {
      width: 100%;
      background: #ffffff;
      border-radius: 5px;

      .MembershipBox {
        padding: 15px;
      }

      .MembershipContent {
        margin-top: 30px;
        margin-bottom: 30px;

        p {
          line-height: 20px;
        }

        p:last-child {
          margin-top: 20px;
        }
      }

      .MembershipInfo {
        margin-bottom: 20px;

        p {
          margin-bottom: 5px;

          span:last-child {
            margin-left: 5px;
          }
        }
      }

      .copy {
        width: 82px;
        height: 30px;
        background: #12142e;
        border-radius: 5px;
        text-align: center;
        line-height: 30px;
      }
    }
  }

  .fexd_footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background-color: #fff;
    box-shadow: 0px 2px 12px 2px rgba(22, 12, 6, 0.09);

    .icon {
      width: 23px;
      height: 23px;
      margin-bottom: 2px;
    }

    .footer_btn {
      padding: 0 30px;
      height: 100%;

      .cancle {
        width: 100%;
        height: 44px;
        background: #85898c;
        border-radius: 5px;
        text-align: center;
        line-height: 44px;
      }

      .qr {
        width: 189px;
        height: 44px;
        background: #ff7a1f;
        border-radius: 5px;
        text-align: center;
        line-height: 44px;
      }
    }
  }

  // .fexd_footer {
  //   position: fixed;
  //   bottom: 0;
  //   left: 0;
  //   width: 100%;
  //   height: 70px;
  //   background-color: #fff;
  //   box-shadow: 0px 2px 12px 2px rgba(22, 12, 6, 0.09);

  //   .icon {
  //     width: 23px;
  //     height: 23px;
  //     margin-bottom: 2px;
  //   }

  //   .footer_btn {
  //     padding: 0 30px;
  //     height: 100%;

  //     .agree {
  //       width: 140px;
  //       height: 44px;
  //       background: #ff7a1f;
  //       border-radius: 5px;
  //       text-align: center;
  //       line-height: 44px;
  //     }

  //     .cancle {
  //       width: 100%;
  //       height: 44px;
  //       background: #85898c;
  //       border-radius: 5px;
  //       text-align: center;
  //       line-height: 44px;
  //     }

  //     .qr {
  //       width: 100%;
  //       height: 44px;
  //       background: #ff7a1f;
  //       border-radius: 5px;
  //       text-align: center;
  //       line-height: 44px;
  //     }
  //   }
  // }
}
</style>
